package com.demo.core.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.demo.base.model.WebUserForPerson;
import com.demo.base.util.CommonUtil;

@Repository
public class WebDao extends BaseDao{

	/**
	 * 验证手机号的唯一性
	 * @param tel
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public boolean validatePhone(String tel){
		
		Session session = this.getSession();
		Query query = session.createQuery("from WebUserForPerson where tel = :tel");
		query.setString("tel", tel);
		List<WebUserForPerson> list = query.list();
		
		if(CommonUtil.isNull(list)){
			
			return true;
		}else{
			return false;
		}
	}
	
	/**
	 * 验证网上用户（个人）是否已经注册
	 * @param loginName
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public boolean validateLoginNameByPerson(String loginName){
		
		Session session = this.getSession();
		Query query = session.createQuery("from WebUserForPerson where loginName = :loginName");
		query.setString("loginName", loginName);
		List<WebUserForPerson> list = query.list();
		
		if(CommonUtil.isNull(list)){
			return true;
		}
		
		return false;
	}
}
